<?php
namespace app\index\controller;

use think\Request;
use \app\admin\model\Material as MaterialModel;

class Material extends Base
{
    protected $model;
    
    public function __construct(Request $request = null)
    {
        parent::__construct($request);

        $this->model = new MaterialModel();
    }

    public function index($id)
    {
        // 正文
        $data = $this->model->find($id);

        $data->clicks +=1;
        
        @$data->save();

        // banner图
        $banner = $this->category_model->where('id', $data->cid)->value('banner');

        $data->banner = $banner;

        // 产品图册
        $pictures = new \app\admin\model\Pictures();

        $data_pic = $pictures->field('id,thumb,image')
            ->where(['cid'=>$data->cid, 'sid'=>$id, 'status'=>1])
            ->select();

        $this->assign('data', $data);
        $this->assign('data_pic', $data_pic);
        return $this->fetch();
    }

    public function lists()
    {
        $cid = 71;
        // banner,img_title图
        $banner =  $this->category_model->where('id', $cid)->value('banner');

        $data = $this->model->field('id,title,thumb,desc,clicks')
            ->where('status', 1)
            ->order('top')
            ->paginate(6);
            
        $this->assign('data', $data);
        $this->assign('banner', $banner);
        $this->assign('img_title', $img_title);
        return $this->fetch();
    }
}
